﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SignalR;
using SignalR.Hosting.Self;
using SignalR.Hubs;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string url = "http://localhost:8082/";
            var server = new Server(url);

            // Map the default hub url (/signalr)
            server.MapHubs();

            // Start the server
            server.Start();

            Console.WriteLine("Server running on {0}", url);

            // Keep going until somebody hits 'x'
            while (true)
            {
                ConsoleKeyInfo ki = Console.ReadKey(true);
                if (ki.Key == ConsoleKey.X)
                {
                    break;
                }
                else if(ki.Key == ConsoleKey.S)
                {
                    IHubContext clHub = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
                    clHub.Clients.WriteLogMsg("Kataklizma");
                }
            }
        }
        public class MyHub : Hub
        {
            public void Send(string message)
            {
                Clients.WriteLogMsg(message);
            }
            public void toggleBroadcast(string msg)
            {
                Console.WriteLine(msg);
            }
        }

        public interface IWatchable
        {
            bool CanExecute { get; set; }
            void Execute();
        }
        public abstract class BaseWatchable : IWatchable
        {
            public bool CanExecute { get; set; }
            public void Execute()
            {
                if(!CanExecute)
                    return;
                try
                {
                    Body();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            public abstract void Body();
        }
        public class FileWatchable : BaseWatchable
        {
            public override void Body()
            {
                throw new NotImplementedException();
            }
        }
    }
}
